import { Viewer, Entity, ScreenSpaceEventHandler } from "cesium";
import BaseLoader from "../base"
import MeasureTool from "@/cesium/measuring";
import { ICesiumLoader } from "@/types/loader";
import { useCesiumGlobalStore } from "@/store/modules/cesiun-global"


type PlottingOptions = {
    type: string
    handler: ScreenSpaceEventHandler;
}
export default class measuring extends BaseLoader implements ICesiumLoader {
    viewer: Viewer;
    entity: Entity;
    handler: ScreenSpaceEventHandler | null = null
    loader: any;
    constructor(viewer: Viewer, options?: Omit<PlottingOptions, 'handler'>) {
        super(viewer);
        this.viewer = viewer;
        this.handler = new ScreenSpaceEventHandler(this.viewer.scene.canvas);
        this.init(viewer, {
            ...options,
            handler: this.handler
        });
    }

    init(viewer: Viewer, options?: PlottingOptions): void {
        this.loader = new MeasureTool(viewer, options);
        if(options.type === 'kjjl'){
            this.loader.drawLineMeasureGraphics()
        }else if(options.type === 'sjcl'){
            this.loader.drawTrianglesMeasureGraphics()
        }
    }


    getData(): Record<string, any> {
        throw new Error('Method not implemented.');
    }

    getEntity(): Entity | void {
        throw new Error('Method not implemented.');
    }

    remove(): boolean {
        throw new Error('Method not implemented.');
    }

    destroy(): void {
        this.loader.destroy()
        super.removeEscEvent()
        useCesiumGlobalStore().loader = null
    }
}